package com.easy.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easy.common.bean.SysUser;
import com.easy.common.service.IUserService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    IUserService userService;
    @PostMapping("/")
    public ResultData insert(@RequestBody SysUser user){
        SysUser data=userService.insert(user);
        return ResultData.success(data);
    }
    @PutMapping("/")
    public ResultData update(@RequestBody SysUser user){
        SysUser data=userService.update(user);
        return ResultData.success(data);
    }
    @DeleteMapping("/{id}")
    public ResultData delete(@PathVariable Integer id){
        int result=userService.delete(id);
        if (result>=1){
            return ResultData.success();
        }else {
            return ResultData.fail();
        }
    }
    @GetMapping("/{id}")
    public ResultData getByID(@PathVariable Integer id){
        SysUser user=userService.getById(id);
        return ResultData.success(user);
    }
    @GetMapping("/page")
    public ResultData getListByPage(Page page,@RequestBody SysUser user){
        IPage<SysUser> data=userService.getListByPage(page,user);
        return ResultData.success(data);
    }
    @GetMapping("/list")
    public ResultData getList(SysUser user){
        List<SysUser> data=userService.getList(user);
        return ResultData.success(data);
    }


}



